package geektime.jdk.jmx;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
import java.util.Date;

public class JMXBeanTest {
    public static void main(String[] args) throws Exception {
        ApplicationInfo applicationInfo = new ApplicationInfo();
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName objectName = new ObjectName("geektime.java.jmx:name=applicationInfo");
        server.registerMBean(applicationInfo, objectName);
        while (true) {
            System.out.println("Test - " + new Date() + " " +
                applicationInfo.incrementCounter());
            Thread.sleep(1000);
        }
    }
}